function cambiar_login() {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_login";
    document.querySelector('.cont_form_login').style.display = "block";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";

    setTimeout(function() { document.querySelector('.cont_form_login').style.opacity = "1"; }, 400);

    setTimeout(function() {
        document.querySelector('.cont_form_sign_up').style.display = "none";
    }, 200);
}

function cambiar_sign_up(at) {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_sign_up";
    document.querySelector('.cont_form_sign_up').style.display = "block";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function() {
        document.querySelector('.cont_form_sign_up').style.opacity = "1";
    }, 350);

    setTimeout(function() {
        document.querySelector('.cont_form_login').style.display = "none";
    }, 300);

}

function ocultar_login_sign_up() {

    document.querySelector('.cont_forms').className = "cont_forms";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function() {
        document.querySelector('.cont_form_sign_up').style.display = "none";
        document.querySelector('.cont_form_login').style.display = "none";
    }, 500);

}

//登录验证
function loginajax() {

    var phone_email = document.getElementById("phone_email").value;
    var password = document.getElementById("password").value;

    if(phone_email == null || phone_email == '') {

        document.getElementById("phone_email").setAttribute("placeholder", "请输入邮箱");
        document.getElementById("phone_email").focus();
        return;
    }
    if(password == null || password == '') {
        document.getElementById("password").setAttribute("placeholder", "请输入密码");
        document.getElementById("password").focus();
        return;
    }

    //获得ajax引擎
    var xmlhttp;
    if(window.XMLHttpRequest) {
        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp = new XMLHttpRequest();
    } else {
        // IE6, IE5 浏览器执行代码
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //服务器响应有两种类型  一种为responseText（String 类型）一种是responseXml类型
            var data = xmlhttp.responseText;
            if(data == "index") {
                window.location.href = '/';
                document.getElementById("ts").innerHTML = '';
            } else {
                document.getElementById("ts").innerHTML = data;

            }

        }
    }
    xmlhttp.open("post", "/get_login?phone_email=" + phone_email + "&password=" + password, true);

    xmlhttp.send(null);

}

//获取验证码
var countdown = 60;
var phone_code;
var pan = true;

function get_code(val) {
    var phone = document.getElementById("phone");
    if(phone.value.length < 11 && phone.value.length > 0 || phone.value.length > 11) {
        phone.value = '';
        phone.setAttribute("placeholder", "手机号输入有误!");
        phone.focus();
        disabled = 0;
        return;
    }
    //调用异步请求
    if(pan) {
        if(phone.value == null || phone.value == '') {
            phone.setAttribute("placeholder", "请输手机号!");
            phone.focus();
            countdown = 0;
            disabled = 0;

        }else{
            if(codemq(phone.value)) {
                security_code.value = null;
                security_code.setAttribute("placeholder", "该手机号已停机!");
                security_code.focus();
                countdown = 0;

            }
        }

    }
    if(countdown == 0) {
        val.style.backgroundColor = '#f44336';
        val.removeAttribute("disabled");
        val.innerHTML = "获取验证码";
        phone.readOnly = false;
        pan = true;
        countdown = 60;
        disabled = 0;
    } else {
        val.style.backgroundColor = '#B0B0B0';
        phone.readOnly = true;
        val.setAttribute("disabled", true);
        val.innerHTML = "重发送("+countdown+")s";
        countdown--;
        setTimeout(function() {
            get_code(val)
        }, 1000)
    }

}
//消息队列异步请求
function codemq(phoneval) {
    //获得ajax引擎

    var xmlcode;
    if(window.XMLHttpRequest) {
        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlcode = new XMLHttpRequest();
    } else {
        // IE6, IE5 浏览器执行代码
        xmlcode = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlcode.onreadystatechange = function() {
        if(xmlcode.readyState == 4 && xmlcode.status == 200) {
            //服务器响应有两种类型  一种为responseText（String 类型）一种是responseXml类型
            var pcode = xmlcode.responseText;
            console.log(pcode)
            pan = false;
            if(pcode != "1234") {
                phone_code = pcode;
                return true;
            } else {

                return false;
            }
        }
    }

    xmlcode.open("post", "/phoneCode?phone=" + phoneval, true);
    xmlcode.send(null);

}




//提交用户注册信息
function sub_user() {
    var security_code = document.getElementById("security_code");
    var phone = document.getElementById("phone");
    var email = document.getElementById("email");
    var pwd = document.getElementById("pwd");
    var rpwd = document.getElementById("rpwd");
    //非空验证
    if(phone.value == null || phone.value == '') {
        phone.setAttribute("placeholder", "请输手机号!");
        phone.focus();
        return;

    }
    if(email.value == null || email.value == '') {
        email.setAttribute("placeholder", "请输入邮箱地址!");
        email.focus();
        return ;
    }
    if(security_code.value == null || security_code.value == '') {
        security_code.setAttribute("placeholder", "请输入验证码!");
        security_code.focus();
        return ;
    }
    if(pwd.value == null || pwd.value == '') {
        pwd.setAttribute("placeholder", "请输入密码!");
        pwd.focus();
        return ;
    }
    if(rpwd.value == null || rpwd.value == '') {
        rpwd.setAttribute("placeholder", "请再次输入密码!");
        rpwd.focus();
        return;
    }
    //邮箱格式
    if(true) {

    }
    //验证码判断
    if(security_code.value != phone_code) {
        security_code.value = null;
        security_code.setAttribute("placeholder", "验证码错误!");
        security_code.focus();
        return;
    }
    if(pwd.value != rpwd.value) {
        rpwd.value = null;
        rpwd.setAttribute("placeholder", "两次密码不一致!");
        rpwd.focus();
        return ;
    }
    //获得ajax引擎
    var xmlpm;
    if(window.XMLHttpRequest) {
        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlpm = new XMLHttpRequest();
    } else {
        // IE6, IE5 浏览器执行代码
        xmlpm = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var foolpe = true;
    xmlpm.onreadystatechange = function() {
        if(xmlpm.readyState == 4 && xmlpm.status == 200) {
            var epval = xmlpm.responseText;
            if(epval == "email") {
                foolpe = false;
                email.value = null;
                email.setAttribute("placeholder", "邮箱已存在!");
                email.focus();

            } else if(epval == "phone") {
                foolpe = false;
                phone.value = null;
                phone.setAttribute("placeholder", "该手机号已存在!");
                phone.focus();

            }

            alert(epval)

        }
        countdown = 0;
    }

    xmlpm.open("post", "/emailOrphone?email=" + email.value + "&phone=" + phone.value, true);
    xmlpm.send(null);
    alert(foolpe)
    if(foolpe){
        window.location.href="/save_user?phone="+phone.value+"&pwd="+pwd.value+"&email="+email.value;
    }else{
        return;
    }




}



//找回密码



function forpassword() {
    var pecode = document.getElementById("epcode");
    var bool = true;
    //获得ajax引擎
    var xmlpe;
    if(window.XMLHttpRequest) {
        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlpe = new XMLHttpRequest();
    } else {
        // IE6, IE5 浏览器执行代码
        xmlpe = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var zts = document.getElementById("zts");
    xmlpe.onreadystatechange = function() {
        if(xmlpe.readyState == 4 && xmlpe.status == 200) {
            var emailpval = xmlpe.responseText;
            if(emailpval == "email" || emailpval == "phone") {
                zts.innerHTML = "";
            } else {

                zts.innerHTML = "该用户不存在";
                pecode.value = null;
                pecode.focus();
                bool = false;
            }

        }

    }
    var eval = null;
    var pval =  pecode.value;
    xmlpe.open("post", "/emailOrphone?email=" + eval + "&phone=" + pval, true);
    xmlpe.send(null);
    if(bool) {
            document.getElementById("pwd01").style.display = "none";
            document.getElementById("pwd02").style.display = "";
             codemq( pecode.value);
    }

}

function rpassword() {
    var coo = document.getElementById("phoneclode");
    if(coo.value == phone_code) {
        document.getElementById("pwd02").style.display = "none";
        document.getElementById("pwd03").style.display = "";
    } else {
        coo.value = null;
        coo.setAttribute("placeholder", "验证码错误!");
    }
}



//密码重置提交验证
function  pwdsubmit() {
    var pwd = document.getElementById("pwd");
    var rpwd = document.getElementById("rpwd");
    var phone = document.getElementById("epcode").value;
    if(pwd.value == null || pwd.value == '') {
        pwd.setAttribute("placeholder", "请输入密码!");
        pwd.focus();
        return ;
    }
    if(rpwd.value == null || rpwd.value == '') {
        rpwd.setAttribute("placeholder", "请再次输入密码!");
        rpwd.focus();
        return ;
    }
    if(pwd.value != rpwd.value) {
        rpwd.value = null;
        rpwd.setAttribute("placeholder", "两次密码不一致!");
        rpwd.focus();
        return ;
    }

    document.getElementById("phone").value=phone;
    document.getElementById("password").value=rpwd.value;
    document.form.method= "get";
    document.form.action= "/repassword";
    document.form.submit();
    return   true;
}